Page({
  data:{list:{}},
  onLoad({id,encryptedData}){
    id? this.getList(id) :this.getFen(encryptedData)
  },
  async getList(id){
    const {code,data:list} = await wx.http.get('/visitor/'+id)
    if(code!==10000) return wx.utils.toast('什么意思')
    // console.log(list);
    this.setData({
      list
    })
  },
  //分享的函数
  async getFen(encryptedData){
    const {code,data:list} = await wx.http.get('/visitor/share/'+encryptedData)
    if(code!==10000) return wx.utils.toast('别来我这里')
    // console.log(list);
    this.setData({
      list
    })
  },
  onShareAppMessage() {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?encryptedData='+this.data.list.encryptedData,
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png',
    }
  },
  async btnOk(){
    // console.log(1);
   const {path} = await wx.getImageInfo({
      src: this.data.list.url,
    })
    // console.log(res);
    wx.saveImageToPhotosAlbum({
      filePath: path,
      fail:()=>{
        wx.utils.toast('保存失败')
      }
    })
  }
})
